package com.hq.qrcode.controller;

import com.hq.qrcode.websocket.WebSocketServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @ClassName QrCodeLoginController
 * @Description TODO
 * @Author huangzl
 * @Date 2018/10/9 14:59
 * @Version 1.0
 **/
@Controller
@RequestMapping("/qrcodelogin")
public class QrCodeLoginController {

    private Logger logger = LoggerFactory.getLogger(QrCodeLoginController.class);


    /**
     * 描述：PC获取二维码
     */
    @RequestMapping("/getLoginQrCode")
    public String getLoginQrCode() throws IOException {
        return "login";
    }

    /**
     * 描述：PC获取二维码
     */
    @RequestMapping("/success")
    public String success() throws IOException {
        return "success";
    }

    @RequestMapping("/pushVideoListToWeb")
    @ResponseBody
    public Map<String, Object> pushVideoListToWeb(@RequestParam("sceneId") String sceneId) {
        System.out.println("sceneId=="+sceneId);
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            WebSocketServer.sendInfo(sceneId, "有推送消息");
            result.put("operationResult", true);
        } catch (IOException e) {
            result.put("operationResult", false);
        }
        return result;
    }

    /**
     * 描述：唯一标识符
     */
    public String generateUUID() {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replace("-", "");
        Long currentTime = System.currentTimeMillis();
        String currentDate = String.valueOf(currentTime);
        return uuid + currentDate;
    }

}